<template>
  <XForm ref="XForm" v-loading="formLoading" :formList="formList" :formData="formData">
    <template v-slot:btn>
      <XBtn :formData="formData" :XForm="$refs['XForm']" @onSubmit="onSubmit" />
    </template>
  </XForm>
</template>

<script>
import axios from 'axios'
import { XForm } from '@/components/@fhsy/x-tool'
import XBtn from '@/components/common/XBtn'
export default {
  components: { XForm, XBtn },
  data: () => ({
    formLoading: false,
    formList: [
      { label: '仓库', prop: 'warehouse', type: 'XCheckbox', options: [], span: 24 },
      { slot: 'btn', span: 24 }
    ],
    formData: {}
  }),
  created () {
    this.formLoading = true
    axios.get('https://gitee.com/api/v5/search/repositories',
      { params: { q: '码云' } }
    ).then(req => {
      this.formList[0].options = req.data.map(item => ({ value: item.id, label: item.human_name }))
      this.formLoading = false
    }).catch(error => {
      console.error('API 请求异常', error)
      this.formLoading = false
    })
  },
  methods: {
    onSubmit () {
      this.$message(`回调: ${JSON.stringify(this.formData)}`)
    }
  }
}
</script>
